﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CalendarAddAndEdit.aspx.cs" Inherits="GovernmentOfficeProject.LevelViewUI.CalendarEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>日程详细</title>    
    <link href="/css/calendarEdit.css" rel="stylesheet" type="text/css" />       
    <link href="/css/dp.css" rel="stylesheet" />    
    <link href="/css/dropdown.css" rel="stylesheet" />    
    <link href="/css/colorselect.css" rel="stylesheet" />  
    <link rel="stylesheet" type="text/css" href="/lib/easyui/themes/bootstrap/easyui.css"/>  
    <link rel="stylesheet" type="text/css" href="/lib/easyui/themes/icon.css"/>   
    
    
    <script src="/lib/jquery.min.js" type="text/javascript" ></script>   
    <script src="/lib/easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="/lib/Plugins/Common.js" type="text/javascript"></script>        
    <script src="/lib/Plugins/jquery.colorselect.js" type="text/javascript"></script>
    <script src="/lib/Plugins/datepicker_lang_CH.js" type="text/javascript"></script> 
    <script src="/lib/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript" ></script> 
    <script src="/lib/common.js" type="text/javascript" ></script> 
    <script type="text/javascript">
    
        var id = <%=calendarId %>;
        var isLdClalendar = getQueryStringByName("ldCalendar");
        var buttons = getQueryStringByName("buttons");
        if (!DateAdd || typeof (DateDiff) != "function") {
            var DateAdd = function (interval, number, idate) {
                number = parseInt(number);
                var date;
                if (typeof (idate) == "string") {
                    date = idate.split(/\D/);
                    eval("var date = new Date(" + date.join(",") + ")");
                }
                if (typeof (idate) == "object") {
                    date = new Date(idate.toString());
                }
                switch (interval) {
                    case "y": date.setFullYear(date.getFullYear() + number); break;
                    case "m": date.setMonth(date.getMonth() + number); break;
                    case "d": date.setDate(date.getDate() + number); break;
                    case "w": date.setDate(date.getDate() + 7 * number); break;
                    case "h": date.setHours(date.getHours() + number); break;
                    case "n": date.setMinutes(date.getMinutes() + number); break;
                    case "s": date.setSeconds(date.getSeconds() + number); break;
                    case "l": date.setMilliseconds(date.getMilliseconds() + number); break;
                }
                return date;
            }
        }
        function getH(date) {
            var hour = date.getHours();
            var ret = (hour > 9 ? hour : "0" + hour);
            return ret;
        }
        
        function getM(date){
            var minute = date.getMinutes();
            var ret = (minute > 9 ? minute : "0" + minute);
            return ret;
        }
        
        
        $(document).ready(function (){ 
           
           //权限按钮控制
            if(buttons.indexOf('modify') == -1 && id > 0){
                $("#Savebtn").css("display","none");
            }
            
            if(buttons.indexOf('delete') == -1 && id > 0){
                $("#Deletebtn").css("display","none");
            }
           
            //debugger;
            var DATA_FEED_URL = "/handler/CalendarDatafeed.ashx";
            
            //设置form action
            var ACTION_URL = DATA_FEED_URL+"?method=adddetails&id="+id+"&userId="+getQueryStringByName("userId");
            if(isLdClalendar){
                ACTION_URL = ACTION_URL+"&ldCalendar=true";
            }
            $("#fmEdit").attr("action",ACTION_URL);
            //var arrT = [];
            //var tt = "{0}:{1}";
            //for (var i = 0; i < 24; i++) {
            //    arrT.push({ text: StrFormat(tt, [i >= 10 ? i : "0" + i, "00"]) }, { text: StrFormat(tt, [i >= 10 ? i : "0" + i, "30"]) });
            //}
            var minute = [];
            var i = 0;
            while(i<60){
                minute.push({text:i < 10 ? "0"+i : i+"",value:i < 10 ? "0"+i : i+""});
                i= i+5;
            }
            
            var hour = [];
             for(var i = 0; i < 24 ; i++){
                hour.push({text:i < 10 ? "0"+i : i+"",value:i < 10 ? "0"+i : i+""});
            }
            
            $("#timezone").val(new Date().getTimezoneOffset() / 60 * -1);
           
            
             $("#stpartHour").combobox({
                valueField: 'value',  
                textField: 'text', 
                data:hour
            });
            
             $("#stpartMinute").combobox({
                valueField: 'value',  
                textField: 'text', 
                data:minute
            });
            
             $("#etpartHour").combobox({
                valueField: 'value',  
                textField: 'text', 
                data:hour
            });
            
             $("#smsSendHour").combobox({
                valueField: 'value',  
                textField: 'text', 
                data:hour
            });
            
             $("#smsSendMinute").combobox({
                valueField: 'value',  
                textField: 'text', 
                data:minute
            });
            
             $("#etpartMinute").combobox({
                valueField: 'value',  
                textField: 'text', 
                data:minute
            });
            
            $("smsSendType").combobox({panelHeight:'auto'});
            var check = $("#IsAllDayEvent").click(function (e) {
                if (this.checked) {
                    
                    $("#stpartHour").combobox("setValue","00");
                    $("#etpartHour").combobox("setValue","00");
                    
                    $("#stpartMinute").combobox("setValue","00");
                    $("#etpartMinute").combobox("setValue","00");
                    
                    
                    $("#startTimeContainer").hide();
                    $("#endTimeContainer").hide();
                    
                }else {
                    var d = new Date();
                    var p = 60 - d.getMinutes();
                    if (p > 30) p = p - 30;
                    d = DateAdd("n", p, d);
                    //$("#stparttime").val(getHM(d)).show();
                    //$("#etparttime").val(getHM(DateAdd("h", 1, d))).show();
                    $("#stpartHour").combobox("setValue",getH(d));
                    $("#etpartHour").combobox("setValue",getH(DateAdd("h",1,d)));
                   
                    $("#stpartMinute").combobox("setValue",getM(d));
                    $("#etpartMinute").combobox("setValue",getM(DateAdd("h",1,d)));
                    $("#startTimeContainer").show();
                    
                    if(!noEndTimeCheck[0].checked){
                        $("#endTimeContainer").show();
                    }
                    
                }
            });
            if (check[0].checked) {
                $("#stpartHour").combobox("setValue","00");
                $("#etpartHour").combobox("setValue","00");
                
                $("#stpartMinute").combobox("setValue","00");
                $("#etpartMinute").combobox("setValue","00");
                
                $("#startTimeContainer").hide();
                $("#endTimeContainer").hide();
                
            }
            $("#Savebtn").click(function () { $("#fmEdit").form("submit",{
                url:ACTION_URL,
                onSubmit: function(){
                   
                   var startDate = new Date(Date.parse($("#stpartdate").datebox('getValue')));
                   var endDate = new Date(Date.parse($("#etpartdate").datebox('getValue')));
                   if(startDate > endDate){
                        alert("开始时间不能大于结束时间，请重新选择");
                        return false;
                   }
                   return  $(this).form('validate');
                }, 
                success:function (data) {
                    var data = eval('(' + data + ')'); 
                    alert(data.Msg);
                    if (data.IsSuccess) {
                        CloseModelWindow(null, true);
                }
            }}); });
            $("#Closebtn").click(function () { CloseModelWindow(); });
            $("#Deletebtn").click(function () {
                if (confirm("您确定要删除吗？")) {
                    var param = [{ "name": "calendarId", value: id}];
                    $.post(DATA_FEED_URL + "?method=remove",
                        param,
                        function (data) {
                            if (data.IsSuccess) {
                                alert(data.Msg);
                                CloseModelWindow(null, true);
                            }
                            else {
                                alert("Error occurs.\r\n" + data.Msg);
                            }
                        }
                    , "json");
                }
            });

           // $("#stpartdate,#etpartdate,#smsSendDate").datepicker({ picker: "<button class='calpick'></button>" });
            var cv = $("#colorvalue").val();
            if (cv == "") {
                cv = "-1";
            }
            $("#calendarcolor").colorselect({ title: "Color", index: cv, hiddenid: "colorvalue" });
            //to define parameters of ajaxform
            var options = {
                beforeSubmit: function () {
                    return true;
                },
                dataType: "json",
                success: function (data) {
                    alert(data.Msg);
                    if (data.IsSuccess) {
                        CloseModelWindow(null, true);
                    }
                }
            };
            
            var mess = "";
            $.extend($.fn.validatebox.defaults.rules, {
                date: {
                    validator: function(value) {
                        return /^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3-9]|1[0-2])[\/\-\.](?:29|30))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3,5,7,8]|1[02])[\/\-\.]31)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:16|[2468][048]|[3579][26])00[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1-9]|1[0-2])[\/\-\.](?:0?[1-9]|1\d|2[0-8]))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?:\d{1,3})?)?$/.test(value);
                        
                    },message: '请输入正确的日期'
                },
                title: {
                    validator: function(value) {
                        return /^[^$\<\>]+$/.test(value);
                    },message: '不允许输入$<>等符号'
                }
            });
                        
            
            function showerror(error, target) {
                var pos = target.position();
                var height = target.height();
                var newpos = { left: pos.left, top: pos.top + height + 2 }
                var form = $("#fmEdit");
                error.appendTo(form).css(newpos);
            }
            
            //设置新建日程 默认日期及时间
            if(id == 0){
                var d = new Date();
                var p = 60 - d.getMinutes();
                if (p > 30) p = p - 30;
                d = DateAdd("n", p, d);
                $("#stpartdate").datebox("setValue",d.getFullYear()+"/"+(d.getMonth()+1)+"/"+d.getDate());
                $("#etpartdate").datebox("setValue",d.getFullYear()+"/"+(d.getMonth()+1)+"/"+d.getDate());
                $("#stpartHour").combobox('setValue',getH(d));
                $("#etpartHour").combobox("setValue",getH(DateAdd("h",1,d)));
                
                $("#stpartMinute").combobox("setValue",getM(d));
                $("#etpartMinute").combobox("setValue",getM(DateAdd("h",1,d)));
           }
            
            
            var smsSendType = $("#smsSendType").combobox({onSelect:function(rec){
                var value = rec.value;
                if(value == 0){
                    $("#smsSendDateContainer").hide();
                    $("#smsBeforeMinuteContainer").hide();
                }else if(value == 1){
                    $("#smsSendDateContainer").show();
                    $("#smsBeforeMinuteContainer").hide();
                }else if(value == 2){
                    $("#smsSendDateContainer").hide();
                    $("#smsBeforeMinuteContainer").show();
                }
            }});
            
            if(smsSendType[0].options[0].selected){
                $("#smsSendDateContainer").hide();
                $("#smsBeforeMinuteContainer").hide();
            }
            if(smsSendType[0].options[1].selected){
                 $("#smsSendDateContainer").show();
                 $("#smsBeforeMinuteContainer").hide();
            }
            if(smsSendType[0].options[2].selected){
                $("#smsSendDateContainer").hide();
                $("#smsBeforeMinuteContainer").show();
            }
            
            var isSms = $("#isSms_n,#isSms_y").click(function () {
                if (this.value == 0) {
                     $("#smsAlertSettingContainer").hide();
                }else{
                    $("#smsAlertSettingContainer").show();
                }
            });
            
            if(isSms[0].checked){
                $("#smsAlertSettingContainer").hide();
            }else{
                $("#smsAlertSettingContainer").show();
            }
            
            //添加领导日程时，状态只能是公开
            if(isLdClalendar){
                $("#status1").attr("disabled","false");
                $("#status2").attr("disabled","false");
                $("#status3").attr("checked","true");
            }
            
            //短信预览
            $("#smsPreview").click(function () {
                var url = ACTION_URL.replace("adddetails","smsProview");
                 $("#fmEdit").form('submit',{
                    url:url,
                    success:function (data) {
                        alert(data);
                    }
                });  
             });
             
             //未知结束时间点击事件
             var noEndTimeCheck = $("#NoEndTime").click(function () {
                if(this.checked){
                    $("#etpartdateContainer").hide();
                    $("#endTimeContainer").hide();
                }else{
                    $("#etpartdateContainer").show();
                    if(!check[0].checked){
                        $("#endTimeContainer").show();
                    }
                }
             }); 
             
             //未知结束时间初始化
             if(noEndTimeCheck[0].checked){
                $("#etpartdateContainer").hide();
                $("#endTimeContainer").hide();
             }
                    
        });
        
    </script>      
    <style type="text/css">     
    .calpick     {        
        width:16px;   
        height:16px;     
        border:none;        
        cursor:pointer;        
        background:url("/css/images/cal.gif") no-repeat center 2px;        
        margin-left:-22px;    
    }
    #dateContainer div    
    {
        float:left;
    }
    .line{border-bottom:1px solid #ccc; padding-top:3px;width:100%; margin-bottom:3px;}  
    .title{width:80px; text-align:right;float:left;padding:5px 10px 5px 0;}
    .clear{clear:left;} 
    </style> 
</head>
<body>
    <div>
        <div>      
        <div class="toolBotton">           
        <a id="Savebtn" class="imgbtn">                
          <span class="Save"  title="保存日程">保存(<u>S</u>)
          </span>          
        </a>                           
        <!-- <?php if(isset($event)){ ?> -->
        <%if (calendarEntity != null && calendarEntity.SceID > 0)
          { %>
        <a id="Deletebtn" class="imgbtn" href="javascript:void(0);">                    
          <span class="Delete" title="删除当前日程">删除(<u>D</u>)
          </span>                
        </a>     
        <%} %>        
        <!-- <?php } ?> -->           
        <a id="Closebtn" class="imgbtn" href="javascript:void(0);">                
          <span class="Close" title="关闭窗口" >关闭
          </span>
        </a>                  
      </div>                  
      <div style="clear: both">         
      </div>        
      <div class="infocontainer">            
        <form    class="fform" id="fmEdit" method="post" action="/handler/CalendarDatafeed.ashx?method=adddetails&id=<%=calendarId%>">                 
          <div class="fm">                         
            <div id="calendarcolor" title="颜色" style="height:20px;">
            </div>
            <input MaxLength="200" class="easyui-validatebox" data-options="required:true,validType:'title',missingMessage:'不能为空',tipPosition:'right'"  id="Subject" name="Subject" style="width:85%;height:18px" type="text" value="<%=calendarEntity.Title%>" />                     
            <input id="colorvalue" name="colorvalue" type="hidden" value="<%=calendarEntity.Color %>" />                
           </div>
                               
          <div class="fm">                                       
            <div id="dateContainer" > 
              <% 
                  string startDate = "";
                  string startTime = "";
                  string endDate = "";
                  string endTime = "";
                  string startHour = "";
                  string startMinute = "";
                  string endHour = "";
                  string endMinute = "";
                  if (calendarEntity.StartTime != null && calendarEntity.EndTime != null)
                  {
                      string[] startDateTime = calendarEntity.StartTime.Split(' ');
                      string[] endDateTime = calendarEntity.EndTime.Split(' ');
                      startDate = startDateTime[0];
                      startTime = startDateTime[1].Substring(0,5);
                      endDate = endDateTime[0];
                      endTime = endDateTime[1].Substring(0, 5);

                      startHour = startDateTime[1].Substring(0, 2);
                      startMinute = startDateTime[1].Substring(3, 2);

                      endHour = endDateTime[1].Substring(0, 2);
                      endMinute = endDateTime[1].Substring(3, 2);
                  }
                  
               %> 
              <div >
                    <input MaxLength="10" class="easyui-datebox" data-options="required:true,validType:'date'"  id="stpartdate" name="stpartdate" style="padding-left:2px;width:90px;" type="text" value="<%=startDate%>" /> 
              </div>               
              <div id="startTimeContainer" >
                <input MaxLength="2" class="easyui-combobox" id="stpartHour" type="text" name="stpartHour" style="width:40px;" value="<%=startHour %>"/> 时
                <input MaxLength="2" class="easyui-combobox" id="stpartMinute" type="text" name="stpartMinute" style="width:40px;" value="<%=startMinute %>"/> 分
              </div>                      
              <div >　—　</div>
              <div id="etpartdateContainer">
                <input MaxLength="10" class="easyui-datebox" data-options="required:true,validType:'date'"   id="etpartdate" name="etpartdate" style="padding-left:2px;width:90px;" type="text" value="<%=endDate%>" />                       
              </div >                       
              <div id="endTimeContainer" >
                <input MaxLength="2" class="required timeHour easyui-combobox" id="etpartHour" name="etpartHour" style="width:40px;"  value="<%=endHour %>" /> 时
                <input MaxLength="2" class="easyui-combobox" id="etpartMinute" name="etpartMinute" style="width:40px;"  value="<%=endMinute %>" /> 分
              </div>
              
               <div style="float:left">
                    <input id="NoEndTime" name="NoEndTime" type="checkbox"  value="1" <%if(calendarEntity.NoEndTime > 0)Response.Write("checked"); %>/>
                 未知结束
               </div>  
               
               <div>
                  &nbsp;<input id="IsAllDayEvent" name="IsAllDayEvent" type="checkbox" value="1" <%if(calendarEntity.IsAllDayEvent > 0)Response.Write("checked"); %>/> 全天日程
              </div>                
            </div> 
            <div class="clear"></div>                 
          </div>  
          
          <div class="line"></div>
          
          <div class="fm">                    
            <div class="title" style>地点</div>                    
            <input MaxLength="200" id="Location" name="Location" style="width:75%;" type="text" value="<%=calendarEntity.Location %>" />                 
            <div class="clear"></div>  
          </div>
                           
          <div class="fm">                    
            <div class="title">日程描述</div>                    
            <textarea cols="20" id="Description" name="Description" rows="2" style="width:75%; height:70px"><%Response.Write(calendarEntity.Content); %></textarea>                
            <div class="clear"></div>  
          </div> 
          
           <div class="line"></div>
          
          <div class="fm">                    
            <div class="title">短信提醒</div> 
            <div style="float:left;padding:4px 4px;">       
                <input type="radio" id="isSms_n" name="isSms" value="0" <%if(calendarEntity.IsSms == 0)Response.Write("checked"); %> />否
                <input type="radio" id="isSms_y" name="isSms" value="1" <%if(calendarEntity.IsSms == 1)Response.Write("checked"); %>/>是 
            </div>
            <div class="clear"></div>
          </div>
          
          <div class="fm" id="smsAlertSettingContainer" style="display:none;">                    
            <div class="title">提醒设置</div> 
             <div style="float:left;padding:4px 0 4px 0;">
                <div style="float:left">
                    <select id="smsSendType" name="smsSendType" class="easyui-combobox" style="width:80px" data-options="panelHeight:80">
		                <option value="0" <%if(calendarEntity.SmsReady.RdySendType == 0)Response.Write("selected"); %>>立即发送</option>
		                <option value="1" <%if(calendarEntity.SmsReady.RdySendType == 1)Response.Write("selected"); %>>定时发送</option>
		                <option value="2" <%if(calendarEntity.SmsReady.RdySendType == 2)Response.Write("selected"); %>>提前发送</option>
		            </select>
                 </div> 
                 
                 <% 
                     string smsSendDate = "";
                     string smsSendHour = "";
                     string smsSendMinute = "";
                     if (calendarEntity.SmsReady.RdyReadySendTime != null)
                     {
                         string[] readySendTime = calendarEntity.SmsReady.RdyReadySendTime.Split(' ');
                         smsSendDate = readySendTime[0];
                         smsSendHour = readySendTime[1].Substring(0, 2);
                         smsSendMinute = readySendTime[1].Substring(3, 2);
                     }
                 %>              
		        <div id="smsSendDateContainer" style="float:left;display:none;">
                    <input MaxLength="10" class="easyui-datebox" id="smsSendDate" name="smsSendDate" style="padding-left:2px;width:90px;" value ="<%=smsSendDate %>"/>
                    <input MaxLength="2" class="easyui-combobox" id="smsSendHour" name="smsSendHour" style="width:40px;" value ="<%=smsSendHour %>"/> 时
                    <input MaxLength="2" class="easyui-combobox" id="smsSendMinute" name="smsSendMinute" style="width:40px;"  value ="<%=smsSendMinute %>"/> 分 
                </div>
                
                
                <div id="smsBeforeMinuteContainer" style="float:left;display:none;">
                    <select id="smsBeforeMinute" name="smsBeforeMinute" class="easyui-combobox" data-options="panelHeight:100">
		                <option value="5"  <%if(calendarEntity.SmsReady.RdyBeforeMinute == 5)Response.Write("selected"); %>>提前5分钟</option>
		                <option value="10" <%if(calendarEntity.SmsReady.RdyBeforeMinute == 10)Response.Write("selected"); %>>提前10分钟</option>
		                <option value="15" <%if(calendarEntity.SmsReady.RdyBeforeMinute == 15)Response.Write("selected"); %>>提前30分钟</option>
		                <option value="30" <%if(calendarEntity.SmsReady.RdyBeforeMinute == 30)Response.Write("selected"); %>>提前60分钟</option>
		            </select>
		        </div>
		        <div style="float:left;padding-left:15px;"><a href="javascript:void(0)" id="smsPreview">短信预览</a></div>
		    </div>
		    <div class="clear"></div>        
          </div>  
          <div class="clear"></div>  
          
          <div class="fm">               
            <div class="title">日程性质</div>
            <div style="float:left;padding:4px 0 4px 0;">                
                 <input type="radio" id="status1" name="status" value="1" <%if(calendarEntity.Status == 1)Response.Write("checked"); %>/>默认
                 <input type="radio" id="status2" name="status" value="2" <%if(calendarEntity.Status == 2)Response.Write("checked"); %>/> 私人
                 <input type="radio" id="status3" name="status" value="3" <%if(calendarEntity.Status == 3)Response.Write("checked"); %>/> 公开            
            </div>
            <div class="clear"></div>     
          </div> 
          
           <div class="line"></div>
           
           <% if (calendarId > 0 && calendarEntity.CreateUser != null)
              {%>
           <div class="fm">               
            <div class="title">创建信息</div>
            <div style="padding:5px 0 5px 0;">                
                 <%=calendarEntity.CreateTime%> 由[<%=calendarEntity.CreateUser.RealName%>] 创建
            </div>
            <div class="clear"></div>     
          </div> 
           <%} %>
           
           <% if (calendarId > 0 && calendarEntity.ModifyUser != null)
              {%>
          <div class="fm">                 
            <div class="title">修改信息</div>
            <div style="padding:5px 0 5px 0;">                
                 <%=calendarEntity.ModifyTime%> 由[<%=calendarEntity.ModifyUser.RealName%>] 最后修改
            </div>
            <div class="clear"></div>     
          </div> 
           <%} %>
          
                      
          <input id="timezone" name="timezone" type="hidden" value="" />           
        </form>         
      </div>         
    </div>
    </div>
</body>
</html>
